import java.util.HashMap;
import java.util.Map;

public class Solution {

    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> hashMap = new HashMap<>();
        for (int value = 0; value < nums.length; value++){
            if (hashMap.containsKey(target - nums[value])){
                return new int[] {value, hashMap.get(target - nums[value])};
            }
            hashMap.put(nums[value], value);
        }
        throw new IllegalArgumentException("未找到结果");
    }

    public static void main(String[] args) {
        int[] nums = {1, 2, 7, 6};
        int target = 5;

        Solution solution = new Solution();
        int[] result = solution.twoSum(nums, target);
        for (int i = 0; i < 2; i++){
            System.out.println(result[i]);
        }
    }
}
